package com.order.staffrole.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.order.staffrole.domain.OrderStaffRole;
import com.order.staffrole.service.IOrderStaffRoleService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 员工角色管理Controller
 * 
 * @author huhu
 * @date 2020-08-20
 */
@Controller
@RequestMapping("/order/staffrole")
public class OrderStaffRoleController extends BaseController
{
    private String prefix = "order/staffrole";

    @Autowired
    private IOrderStaffRoleService orderStaffRoleService;

    @RequiresPermissions("order:staffrole:view")
    @GetMapping()
    public String staffrole()
    {
        return prefix + "/staffrole";
    }

    /**
     * 查询员工角色管理列表
     */
    @RequiresPermissions("order:staffrole:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OrderStaffRole orderStaffRole)
    {
        startPage();
        List<OrderStaffRole> list = orderStaffRoleService.selectOrderStaffRoleList(orderStaffRole);
        return getDataTable(list);
    }

    /**
     * 导出员工角色管理列表
     */
    @RequiresPermissions("order:staffrole:export")
    @Log(title = "员工角色管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OrderStaffRole orderStaffRole)
    {
        List<OrderStaffRole> list = orderStaffRoleService.selectOrderStaffRoleList(orderStaffRole);
        ExcelUtil<OrderStaffRole> util = new ExcelUtil<OrderStaffRole>(OrderStaffRole.class);
        return util.exportExcel(list, "staffrole");
    }

    /**
     * 新增员工角色管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存员工角色管理
     */
    @RequiresPermissions("order:staffrole:add")
    @Log(title = "员工角色管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OrderStaffRole orderStaffRole)
    {
        return toAjax(orderStaffRoleService.insertOrderStaffRole(orderStaffRole));
    }

    /**
     * 修改员工角色管理
     */
    @GetMapping("/edit/{staffRoleId}")
    public String edit(@PathVariable("staffRoleId") Long staffRoleId, ModelMap mmap)
    {
        OrderStaffRole orderStaffRole = orderStaffRoleService.selectOrderStaffRoleById(staffRoleId);
        mmap.put("orderStaffRole", orderStaffRole);
        return prefix + "/edit";
    }

    /**
     * 修改保存员工角色管理
     */
    @RequiresPermissions("order:staffrole:edit")
    @Log(title = "员工角色管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OrderStaffRole orderStaffRole)
    {
        return toAjax(orderStaffRoleService.updateOrderStaffRole(orderStaffRole));
    }

    /**
     * 删除员工角色管理
     */
    @RequiresPermissions("order:staffrole:remove")
    @Log(title = "员工角色管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(orderStaffRoleService.deleteOrderStaffRoleByIds(ids));
    }
}
